<?php

namespace app\common\model;

use think\Model;


class Disease extends Model
{

    

    

    // 表名
    protected $name = 'disease';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
//        'deteletime_text'
    ];
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weight' => $row[$pk]]);
        });
    }

    



    public function getDeteletimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['deteletime']) ? $data['deteletime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

//    protected function setDeteletimeAttr($value)
//    {
//        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
//    }

    public function hospital()
    {
        return $this->belongsTo('Hospital','recommend_h','id',[],'LEFT')->field('id,name,image,tag');
    }

    public function office()
    {
        return $this->belongsTo('office','office_id','id',[],'LEFT')->field('id,type_name');
    }
}
